﻿using System;

namespace 飞行棋
{
    class Program
    {
        //我们用静态字段来模拟全局变量
        public  static int[] Maps = new int[100];
        //声明一个静态数组用来存储玩家A跟玩家B的坐标。
        static int[] PlayerPos = new int[2];
        //存储两个玩家的姓名
        static string[] PlayerNumbers = new string[2];

        static bool[] Flags =new bool[2];//Flags[0]默认是false Flags[1]默认也是false
        static void Main(string[] args)
        {
            Gameshow();//画游戏的标题
            #region 输入姓名
            Console.WriteLine("请输入玩家A的姓名");
            PlayerNumbers[0] = Console.ReadLine();
            while (PlayerNumbers[0] == "")
            {
                Console.WriteLine("玩家A的姓名不能为空，请重新输入");
                PlayerNumbers[0] = Console.ReadLine();
            }
            Console.WriteLine("请输入玩家B的姓名");
            PlayerNumbers[1] = Console.ReadLine();
            while (PlayerNumbers[1] == "" || PlayerNumbers[1] == PlayerNumbers[0])
            {
                if (PlayerNumbers[1] == "")
                {
                    Console.WriteLine("玩家B的姓名不能为空，请重新输入");
                    PlayerNumbers[1] = Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("玩家B的姓名不能跟玩家A的姓名相同，请重新输入");
                    PlayerNumbers[1] = Console.ReadLine();
                }
            }
            #endregion
            //玩家姓名输入成功后，我们首先应该清屏
            Console.Clear();//请屏
            Gameshow();
            Console.WriteLine("{0}的士兵用A表示",PlayerNumbers[0]);
            Console.WriteLine("{0}的士兵用B表示",PlayerNumbers[1]);
            //在画地图之前首先一定要初始化地图
            InitailMap();//初始化地图
            DrawMap();//画地图
            //当玩家A跟玩家B没有一个到终点，俩个人不停的玩游戏。
            while (PlayerPos[0] < 99 && PlayerPos[1] < 99)
            {
                if (Flags[0] == false)
                {
                    PlayGame(0);
                }
                else
                {
                    Flags[0] = false;
                }
                if (PlayerPos[0] >= 99)
                {
                    Console.WriteLine("恭喜玩家{0}获胜，奖励一个爱心",PlayerNumbers[0]);
                }
                if (Flags[1] == false)
                {
                    PlayGame(1);
                }
                else
                {
                    Flags[1] = false;
                }
                if (PlayerPos[1] >= 99)
                {
                    Console.WriteLine("恭喜玩家{0}获胜，奖励一个爱心",PlayerNumbers[1]);
                    break;
                }
            }
            shengli();
            Console.ReadKey();
        }
        #region  开头 初始化 第一横行
        /// <summary>
        /// 胜利
        /// </summary>
        public static void shengli()
        {
            Console.WriteLine("        ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥");
            Console.WriteLine("      ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥");
            Console.WriteLine("        ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥我");
            Console.WriteLine("♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥不");
            Console.WriteLine("            ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥会");
            Console.WriteLine("            ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥搞");
            Console.WriteLine("               ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥爱");
            Console.WriteLine("               ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥心");
            Console.WriteLine(               "♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥将");
            Console.WriteLine("                ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥就");
            Console.WriteLine("                 ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥这");
            Console.WriteLine("                 ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥看");
            Console.WriteLine("                  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥吧");
            Console.WriteLine("♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥");
            Console.WriteLine("♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥");
            Console.WriteLine("♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥");
            Console.WriteLine("♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥");
            Console.WriteLine("♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥");
            Console.WriteLine("♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥");
            Console.WriteLine("♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥");
            Console.WriteLine("                     ♥♥♥♥♥♥♥♥♥♥♥♥♥♥                     ");
            Console.WriteLine("                      ♥♥♥♥♥♥♥♥♥♥♥♥♥                      ");
            Console.WriteLine("                       ♥♥♥♥♥♥♥♥♥♥♥♥                       ");
            Console.WriteLine("                        ♥♥♥♥♥♥♥♥♥♥♥                        ");
            Console.WriteLine("                         ♥♥♥♥♥♥♥♥♥♥                         ");
            Console.WriteLine("                          ♥♥♥♥♥♥♥♥♥                           ");
            Console.WriteLine("                           ♥♥♥♥♥♥♥♥                            ");
            Console.WriteLine("                            ♥♥♥♥♥♥♥                             ");
            Console.WriteLine("                             ♥♥♥♥♥♥                              ");
            Console.WriteLine("                              ♥♥♥♥♥                                ");
            Console.WriteLine("                               ♥♥♥♥                                  ");
            Console.WriteLine("                                ♥♥♥                                    ");
            Console.WriteLine("                                 ♥♥                                     ");
            Console.WriteLine("                                  ♠                                        ");
        }

        /// <summary>
        /// 开头
        /// </summary>
        public static void Gameshow()
        {
            //画游戏图
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("************************");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("************************");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("******耀耀版飞行棋******");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("************************");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("************************");
        }
        /// <summary>
        /// 特殊图标
        /// </summary>
        public static void InitailMap()
        {
            int[] luckyturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘
            for (int i = 0; i < luckyturn.Length; i++)
            {
                Maps[luckyturn[i]] = 1;
            }
            int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷
            for (int i = 0; i < landMine.Length; i++)
            {
                Maps[landMine[i]] = 2;
            }
            int[] pause = { 9, 27, 60, 93 };//暂停
            for (int i = 0; i < pause.Length; i++)
            {
                Maps[pause[i]] = 3;
            }
            int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道
            for (int i = 0; i < timeTunnel.Length; i++)
            {
                Maps[timeTunnel[i]] = 4;
            }
        }
        /// <summary>
        /// 地图
        /// </summary>
        public static void DrawMap()
        {
           
            Console.WriteLine("图例：□表示普通方块 卍表示幸运轮盘 ☆表示地雷 囍表示暂停 ○时空隧道");
            
            //第一横行
            //如果玩家A和玩家B的坐标相同，画一个"<>"
            for (int i = 0; i < 30; i++)
            {
                Console.Write(DrawstringMap(i));
            }//for
            #endregion
            //画完第一行后应该换行
            //第一竖行
            Console.WriteLine();
            for (int i = 30; i < 35; i++)
            {
                for (int j = 0; j <= 28; j++)
                {
                    Console.Write("　");
                }
                Console.Write(DrawstringMap(i));
                Console.WriteLine();
            }
            //第二横行
            for (int i = 64; i >= 35; i--)
            {
                Console.Write(DrawstringMap(i));
            }
            //画完第二横行应该换行
            //第二竖行
            Console.WriteLine();
            for (int i = 65; i < 69; i++)
            {
                Console.WriteLine(DrawstringMap(i));
            }

            //第三横行
            for (int i = 70; i < 99; i++)
            {
                Console.Write(DrawstringMap(i));
            }
            //画完最后一行换行
            Console.WriteLine();
        }

        /// <summary>
        /// 画图
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public static string DrawstringMap(int i)
        {
            #region 画图
            string str = "";
            if (PlayerPos[0] == PlayerPos[1] && PlayerPos[1] == i)
            {
                str = "<>";
            }
            else if (PlayerPos[0] == i)
            {
                str = "A";
            }
            else if (PlayerPos[1] == i)
            {
                str = "B";
            }
            else
            {
                switch (Maps[i])
                {
                    case 0:
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        str = "□";//表示普通方块
                        break;
                    case 1:
                        Console.ForegroundColor = ConsoleColor.White;
                        str = "卍";//表示幸运轮盘
                        break;
                    case 2:
                        Console.ForegroundColor = ConsoleColor.Gray;
                        str = "☆";//表示地雷
                        break;
                    case 3:
                        Console.ForegroundColor = ConsoleColor.Red;
                        str = "囍";//表示暂停
                        break;
                    case 4:
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                        str = "○";//表示时空隧道
                        break;
                }//switch
            }//else
            return str;
            #endregion
        }
        /// <summary>
        /// 玩游戏
        /// </summary>
        public static void PlayGame(int PlayerNumber)
        {
            Random r = new Random();
            int rNumber = r.Next(1, 7);
            Console.WriteLine("{0}按任意键掷骰子", PlayerNumbers[PlayerNumber]);
            Console.ReadKey(true);
            Console.WriteLine("{0}掷出了{1}", PlayerNumbers[PlayerNumber],rNumber);
            PlayerPos[PlayerNumber] += rNumber;
            ChangePos();
            Console.ReadKey(true);
            Console.WriteLine("{0}按任意键开始行动", PlayerNumbers[PlayerNumber]);
            Console.ReadKey(true);
            Console.WriteLine("{0}行动完了", PlayerNumbers[PlayerNumber]);
            Console.ReadKey(true);
            //玩家A可能踩到玩家B 方块 幸运轮盘 地雷 暂停 时空隧道
            if (PlayerPos[PlayerNumber] == PlayerPos[1- PlayerNumber])
            {
                Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退6格", PlayerNumbers[PlayerNumber], PlayerNumbers[1- PlayerNumber], PlayerNumbers[1- PlayerNumber]);
                PlayerPos[1- PlayerNumber] -= 6;
                ChangePos();
                Console.ReadKey(true);
            }
            else//踩到了机关
            {
                switch (Maps[(PlayerPos[PlayerNumber])])
                {
                    case 0:
                        Console.WriteLine("玩家{0}什么都没有踩到，安全", PlayerNumbers[PlayerNumber]);
                        Console.ReadKey(true);
                        break;
                    case 1:
                        Console.WriteLine("玩家{0}踩到了幸运轮盘，请选择：1--交换位置 2--轰炸对方，使对方退6格", PlayerNumbers[PlayerNumber]);
                        string input = Console.ReadLine();
                        while (true)
                        {
                            if (input == "1")
                            {
                                Console.WriteLine("玩家{0}选择跟玩家{1}交换位置", PlayerNumbers[PlayerNumber], PlayerNumbers[1- PlayerNumber]);
                                Console.ReadKey(true);
                                int temp = PlayerPos[PlayerNumber];
                                PlayerPos[PlayerNumber] = PlayerPos[1- PlayerNumber];
                                PlayerPos[1- PlayerNumber] = temp;
                                Console.WriteLine("交换成功，按任意键继续游戏");
                                Console.ReadKey(true);
                                break;
                            }
                            else if (input == "2")
                            {
                                Console.WriteLine("玩家{0}选择轰炸玩家{1}，玩家{2}退6格", PlayerNumbers[PlayerNumber], PlayerNumbers[1- PlayerNumber], PlayerNumbers[1- PlayerNumber]);
                                Console.ReadKey(true);
                                PlayerPos[1- PlayerNumber] -= 6;
                                ChangePos();
                                Console.WriteLine("轰炸成功，按任意键继续游戏");
                                Console.ReadKey(true);
                                break;
                            }
                            else
                            {
                                Console.WriteLine("输入错误，只能输入 1--交换位置 2--轰炸对方，请重新输入");
                                input = Console.ReadLine();
                            }
                        }
                        break;
                    case 2:
                        Console.WriteLine("玩家{0}踩到了地雷，退6格", PlayerNumbers[PlayerNumber]);
                        Console.ReadKey(true);
                        PlayerPos[PlayerNumber] -= 6;
                        ChangePos();
                        break;
                    case 3:
                        Console.WriteLine("玩家{0}踩到了暂停，暂停一回合", PlayerNumbers[PlayerNumber]);
                        Flags[PlayerNumber] = true;
                        Console.ReadKey(true);
                        break;
                    case 4:
                        Console.WriteLine("玩家{0}踩到了时空隧道，前进10格", PlayerNumbers[PlayerNumber]);
                        PlayerPos[PlayerNumber] += 10;
                        ChangePos();
                        Console.ReadKey(true);
                        break;
                }
            }
            ChangePos();
            Console.Clear();
            DrawMap();
        }
        /// <summary>
        /// 当玩家坐标发生改变
        /// </summary>
        public static void ChangePos()
        {
            if (PlayerPos[0] < 0)
            {
                PlayerPos[0] = 0;
            }
            if (PlayerPos[0] > 99)
            {
                PlayerPos[0] = 99;
            }
            if (PlayerPos[1] < 0)
            {
                PlayerPos[1] = 0;
            }
            if (PlayerPos[1] > 99)
            {
                PlayerPos[1] = 99;
            }
        }
        
    }
}
